Joining array¶

In [6]:
import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.concatenate((arr1, arr2))

print(arr)
[1 2 3 4 5 6]

Stack Functions¶

In [7]:
import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.stack((arr1, arr2), axis=1)

print(arr)
[[1 4]
 [2 5]
 [3 6]]

Stacking Along Rows¶

In [8]:
import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.hstack((arr1, arr2))

print(arr)
[1 2 3 4 5 6]

Stacking Along Columns¶

In [9]:
import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.vstack((arr1, arr2))

print(arr)
[[1 2 3]
 [4 5 6]]

Height (depth)¶

In [11]:
import numpy as np

arr1 = np.array([1, 2, 3])

arr2 = np.array([4, 5, 6])

arr = np.dstack((arr1, arr2))

print(arr)
[[[1 4]
  [2 5]
  [3 6]]]

Sorting Arrays¶

In [12]:
import numpy as np

arr = np.array([3, 2, 0, 1])

print(np.sort(arr))
[0 1 2 3]

Sorting a 2-D Array¶

In [13]:
import numpy as np

arr = np.array([[3, 2, 4], [5, 0, 1]])

print(np.sort(arr))
[[2 3 4]
 [0 1 5]]

Filtering Arrays¶

In [14]:
import numpy as np

arr = np.array([41, 42, 43, 44])

x = [True, False, True, False]

newarr = arr[x]

print(newarr)
[41 43]

Creating the Filter Array¶

In [15]:
import numpy as np

arr = np.array([41, 42, 43, 44])

filter_arr = []


for element in arr:

  if element > 42:
    filter_arr.append(True)
  else:
    filter_arr.append(False)

newarr = arr[filter_arr]

print(filter_arr)
print(newarr)
[False, False, True, True]
[43 44]

Creating Filter Directly From Array¶

In [16]:
import numpy as np

arr = np.array([41, 42, 43, 44])

filter_arr = arr > 42

newarr = arr[filter_arr]

print(filter_arr)
print(newarr)
[False False  True  True]
[43 44]

Random Number¶

from numpy import random

x = random.randint(100)

print(x)

Generate Random Float¶

In [18]:
from numpy import random

x = random.rand()

print(x)
0.9381820419596202

Generate Random Array¶

In [19]:
from numpy import random

x=random.randint(100, size=(5))

print(x)
[84 35  5 67 53]

Random Number From Array¶

In [20]:
from numpy import random

x = random.choice([3, 5, 7, 9])

print(x)
7

Random Distribution¶

In [27]:
from numpy import random

x = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(80))

print(x)
[7 7 5 3 5 7 7 7 7 7 3 7 7 7 7 5 7 7 7 5 7 5 3 5 5 7 7 7 7 5 3 7 7 5 7 7 7
 5 3 3 7 5 7 5 5 5 7 7 7 7 3 7 7 7 5 7 5 5 7 7 7 7 5 7 3 7 7 7 7 5 5 5 5 5
 3 7 5 5 7 5]

Shuffling Arrays¶

In [28]:
from numpy import random
import numpy as np

arr = np.array([1, 2, 3, 4, 5])

random.shuffle(arr)

print(arr)
[3 5 4 1 2]

Generating Permutation of Arrays¶

In [29]:
from numpy import random
import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(random.permutation(arr))
[1 5 4 2 3]
In [30]:
!pip install seaborn
Collecting seaborn
  Downloading seaborn-0.13.2-py3-none-any.whl.metadata (5.4 kB)
Requirement already satisfied: numpy!=1.24.0,>=1.20 in c:\users\admin\anaconda3\envs\abhis-learning\lib\site-packages (from seaborn) (2.2.4)
Collecting pandas>=1.2 (from seaborn)
  Downloading pandas-2.2.3-cp312-cp312-win_amd64.whl.metadata (19 kB)
Collecting matplotlib!=3.6.1,>=3.4 (from seaborn)
  Downloading matplotlib-3.10.1-cp312-cp312-win_amd64.whl.metadata (11 kB)
Collecting contourpy>=1.0.1 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Downloading contourpy-1.3.1-cp312-cp312-win_amd64.whl.metadata (5.4 kB)
Collecting cycler>=0.10 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Using cached cycler-0.12.1-py3-none-any.whl.metadata (3.8 kB)
Collecting fonttools>=4.22.0 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Downloading fonttools-4.56.0-cp312-cp312-win_amd64.whl.metadata (103 kB)
Collecting kiwisolver>=1.3.1 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Downloading kiwisolver-1.4.8-cp312-cp312-win_amd64.whl.metadata (6.3 kB)
Requirement already satisfied: packaging>=20.0 in c:\users\admin\anaconda3\envs\abhis-learning\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (24.1)
Collecting pillow>=8 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Downloading pillow-11.1.0-cp312-cp312-win_amd64.whl.metadata (9.3 kB)
Collecting pyparsing>=2.3.1 (from matplotlib!=3.6.1,>=3.4->seaborn)
  Downloading pyparsing-3.2.2-py3-none-any.whl.metadata (5.0 kB)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\admin\anaconda3\envs\abhis-learning\lib\site-packages (from matplotlib!=3.6.1,>=3.4->seaborn) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in c:\users\admin\anaconda3\envs\abhis-learning\lib\site-packages (from pandas>=1.2->seaborn) (2024.1)
Collecting tzdata>=2022.7 (from pandas>=1.2->seaborn)
  Downloading tzdata-2025.2-py2.py3-none-any.whl.metadata (1.4 kB)
Requirement already satisfied: six>=1.5 in c:\users\admin\anaconda3\envs\abhis-learning\lib\site-packages (from python-dateutil>=2.7->matplotlib!=3.6.1,>=3.4->seaborn) (1.16.0)
Downloading seaborn-0.13.2-py3-none-any.whl (294 kB)
Downloading matplotlib-3.10.1-cp312-cp312-win_amd64.whl (8.1 MB)
   ---------------------------------------- 0.0/8.1 MB ? eta -:--:--
   ---------- ----------------------------- 2.1/8.1 MB 10.7 MB/s eta 0:00:01
   ---------------------- ----------------- 4.5/8.1 MB 11.2 MB/s eta 0:00:01
   --------------------------------- ------ 6.8/8.1 MB 11.3 MB/s eta 0:00:01
   ---------------------------------------- 8.1/8.1 MB 10.2 MB/s eta 0:00:00
Downloading pandas-2.2.3-cp312-cp312-win_amd64.whl (11.5 MB)
   ---------------------------------------- 0.0/11.5 MB ? eta -:--:--
   -------- ------------------------------- 2.4/11.5 MB 12.2 MB/s eta 0:00:01
   ----------------- ---------------------- 5.0/11.5 MB 11.6 MB/s eta 0:00:01
   ------------------------- -------------- 7.3/11.5 MB 11.9 MB/s eta 0:00:01
   ---------------------------------- ----- 10.0/11.5 MB 11.9 MB/s eta 0:00:01
   ---------------------------------------- 11.5/11.5 MB 11.2 MB/s eta 0:00:00
Downloading contourpy-1.3.1-cp312-cp312-win_amd64.whl (220 kB)
Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)
Downloading fonttools-4.56.0-cp312-cp312-win_amd64.whl (2.2 MB)
   ---------------------------------------- 0.0/2.2 MB ? eta -:--:--
   -------------------------------------- - 2.1/2.2 MB 11.7 MB/s eta 0:00:01
   ---------------------------------------- 2.2/2.2 MB 10.3 MB/s eta 0:00:00
Downloading kiwisolver-1.4.8-cp312-cp312-win_amd64.whl (71 kB)
Downloading pillow-11.1.0-cp312-cp312-win_amd64.whl (2.6 MB)
   ---------------------------------------- 0.0/2.6 MB ? eta -:--:--
   ------------------------------- -------- 2.1/2.6 MB 10.7 MB/s eta 0:00:01
   ---------------------------------------- 2.6/2.6 MB 10.1 MB/s eta 0:00:00
Downloading pyparsing-3.2.2-py3-none-any.whl (111 kB)
Downloading tzdata-2025.2-py2.py3-none-any.whl (347 kB)
Installing collected packages: tzdata, pyparsing, pillow, kiwisolver, fonttools, cycler, contourpy, pandas, matplotlib, seaborn
Successfully installed contourpy-1.3.1 cycler-0.12.1 fonttools-4.56.0 kiwisolver-1.4.8 matplotlib-3.10.1 pandas-2.2.3 pillow-11.1.0 pyparsing-3.2.2 seaborn-0.13.2 tzdata-2025.2

Import Seaborn¶

In [31]:
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot([0, 1, 2, 3, 4, 5])

plt.show()
C:\Users\Admin\AppData\Local\Temp\ipykernel_12220\1138594208.py:4: UserWarning: 

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `histplot` (an axes-level function for histograms).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

  sns.distplot([0, 1, 2, 3, 4, 5])
No description has been provided for this image

Plotting a Distplot Without the Histogram¶

In [32]:
import matplotlib.pyplot as plt
import seaborn as sns

sns.distplot([0, 1, 2, 3, 4, 5], hist=False)

plt.show()
C:\Users\Admin\AppData\Local\Temp\ipykernel_12220\3434429482.py:4: UserWarning: 

`distplot` is a deprecated function and will be removed in seaborn v0.14.0.

Please adapt your code to use either `displot` (a figure-level function with
similar flexibility) or `kdeplot` (an axes-level function for kernel density plots).

For a guide to updating your code to use the new functions, please see
https://gist.github.com/mwaskom/de44147ed2974457ad6372750bbe5751

  sns.distplot([0, 1, 2, 3, 4, 5], hist=False)
No description has been provided for this image
In [ ]: